package handler

import (
	"github.com/gin-gonic/gin"
	"hotel_3.27/api/client"
	"hotel_3.27/api/model"
	hotel "hotel_3.27/common/proto"
	"net/http"
)

func SendSms(c *gin.Context) {
	var data model.SendSms
	if err := c.ShouldBind(&data); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	sms, err := client.SendSms(c, &hotel.SendSmsReq{
		Mobile: data.Mobile,
		Source: data.Source,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "短信发送成功",
		"data": sms,
	})
}

func Login(c *gin.Context) {
	var data model.Login
	if err := c.ShouldBind(&data); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	sms, err := client.Login(c, &hotel.LoginReq{
		Mobile: data.Mobile,
		Code:   data.Code,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "用户登录成功",
		"data": sms,
	})
}

func OrderAdd(c *gin.Context) {
	var data model.OrderAdd
	if err := c.ShouldBind(&data); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	sms, err := client.OrderAdd(c, &hotel.OrderAddReq{
		HotelId: data.HotelId,
		Sum:     data.Sum,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "酒店订单添加成功",
		"data": sms,
	})
}

func OrderList(c *gin.Context) {

	sms, err := client.OrderList(c, &hotel.OrderListReq{})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "酒店订单列表展示成功",
		"data": sms,
	})
}
